/**
 * 
 */
package org.picWeb.util;

import java.io.File;
import java.io.IOException;

import lombok.Getter;

//import org.im4java.core.ConvertCmd;
//import org.im4java.core.IMOperation;

/**
 * @author Administrator
 * @version 1.0 org.picWeb.util/ThumbUtil.java 2011-6-27
 */
public class ThumbUtil {
	@Getter
	private int middleWidth;
	@Getter
	private int middleHeight;
	@Getter
	private int smallWidth;
	@Getter
	private int smallHeight;
	@Getter
	private String middleRule;
	@Getter
	private String smallRule;

	/***
	 * @param middleRule
	 * @param smallRule
	 */
	public ThumbUtil(String middleRule, String smallRule) {
		this.middleRule = middleRule;
		this.smallRule = smallRule;

		String[] middle = middleRule.split("-");
		String[] small = smallRule.split("-");

		middleWidth = Integer.valueOf(middle[0]);
		middleHeight = Integer.valueOf(middle[1]);

		smallWidth = Integer.valueOf(small[0]);
		smallHeight = Integer.valueOf(small[1]);
	}

	public void generateThumb(final File file, final String outputFormat, final String middleName, final String smallName) throws IOException {
		Thread t = new Thread("thumbThread") {
			@Override
			public void run() {
				String path = file.getParent() + "/";
				String filePath = file.getPath();
				try {
////					ConvertCmd cmd = new ConvertCmd();
//
//					IMOperation opMiddle = new IMOperation();
//					opMiddle.addImage(filePath);
//					opMiddle.resize(middleWidth, middleHeight);
//					opMiddle.addImage(path + middleName);
//					cmd.run(opMiddle);
//
//					IMOperation opSmall = new IMOperation();
//					opSmall.addImage(filePath);
//					opSmall.resize(smallWidth, smallHeight, '^').gravity("center").extent(smallWidth, smallHeight);
//					opSmall.addRawArgs("-quality", "75");
//					opSmall.addImage(path + smallName);
//					cmd.run(opSmall);
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		};

		t.start();
	}

}
